const app = getApp();
const common = require('../../../utils/common.js');
const api = require('../../../config/api.js');

Page({
  data: {
    imgurl: app.globalData.imgurl,
    avatarUrl: 'http://yanxuan.nosdn.127.net/8945ae63d940cc42406c3f67019c5cb6.png',
		balance: 0,
    isAuthorize: 0,
    memberRankId: 1,
    memberRankName: '普通会员',
		type: 0,
		isBind:1
		
  },
  onLoad: function (options) {
    
	},
	towuyedeatil(){
     wx.navigateTo({
			 url: '/pages/paydetail/index',
		 })
	},
	handleSign(){
		wx.navigateTo({
			url: '/pages/ucenter/signList/index?list=' + JSON.stringify(this.data.dataList),
		})
	},
  onShow: function () {
		this.checkLogin();
		this.signList();
	},
	signList: function(){
		common.request(api.signList, {}, 'post').then(data=>{
			console.log(data)
			if (data.type == 'success') {
				this.setData(data.data)
			}
		})
		},
  checkLogin: function () {
	var memberId = wx.getStorageSync("memberId");
	
    var isAuthorize = 0;
    if (memberId) {
      isAuthorize = 1;
      this.getMemberInfo();
    }
    this.setData({
      isAuthorize: isAuthorize
	});
	if(wx.getStorageSync("isBind") == '1'){
		this.setData({
			isBind:2
		  });
	}
  },
	goLogin: function () {
		if(this.data.isAuthorize){
			return
		}
		wx.navigateTo({
			url: '/pages/shouquan/shouquan'
		});
	},
  getMemberInfo: function () {
    var that = this;
    var data = {};
    common.request(api.MemberInfo, data, 'get').then(function (data) {
      if (data.type == 'success') {
        that.setData({
          nickname: data.data.nickname,
          avatarUrl: data.data.avatarUrl,
					balance: data.data.balance,
          memberRankId: data.data.memberRankId,
          memberRankName: data.data.memberRankName,
					type: data.data.type
        });
	  }
	  if(data.data.isBind){
		  that.setData({
			isBind:2
		  })
	  }
    });
  },
  orderAllurl: function () {
		let url = '/pages/ucenter/order/order?id=0';
		this.checkSkip(url);
	},
	golistpage:function(){
		let url = '/pages/ucenter/huodonglist/index';
		this.checkSkip(url);
	},
	register: function (e) {
		if(e.currentTarget.dataset.type == 'user'){
			let url = '/pages/ucenter/registerinfo/registerinfo';
			this.checkSkip(url);
		}else{
			let url = '/pages/yezhucenter/registerinfo/registerinfo';
			this.checkSkip(url);
		}
	
	},
	memberInfo: function () {
		let url = '/pages/ucenter/improveinfo/improveinfo';
		this.checkSkip(url);
	},
	address: function () {
		let url = '/pages/ucenter/address/address';
		this.checkSkip(url);
	},
	selfRaising: function () {
		let url = '/pages/ucenter/selfRaising/index';
		this.checkSkip(url);
	},
	tuijian: function () {
		let url = '/pages/ucenter/tuijian/tuijian';
		this.checkSkip(url);
	},
	shoucang: function () {
		let url = '/pages/ucenter/collect/collect';
		this.checkSkip(url);
	},
	hexiao: function () {
		let url = '/pages/hexiao/hexiao';
		this.checkSkip(url);
	},
	hexiao1: function () {
		let url = '/pages/hexiao1/hexiao';
		this.checkSkip(url);
	},
	recharge: function () {
		let url = '/pages/ucenter/recharge/recharge';
		this.checkSkip(url);
	},
	balanceRecord: function () {
		let url = '/pages/ucenter/histor_yue/histor_yue';
		this.checkSkip(url);
	},
	checkSkip: function (url) {
		if (!wx.getStorageSync("memberId")) {
			wx.navigateTo({
				url: '/pages/shouquan/shouquan'
			});
		} else {
			wx.navigateTo({
				url: url
			});
		}
	},
	// 获取签到数据
	get_sign: function(){
		var that = this;
		var userId = wx.getStorageSync("userId");
		wx.request({
			url: 'http://服务器公网ip:80/get_sign/'+userId,
			method: "GET",
			success: function (res) {
				if (res.data.status == 1) {
					that.setData({
						total_sign: res.data.data.total,
						signed: res.data.data.signed,
							 })
						 }
				 else{
					 console.log("status error: " + res.data.Exception)
					 }
				 },
			 })
	 },
	 //	点击签到
	 sign:function(){
		 var that = this;
		 var userId = wx.getStorageSync("userId");
		 wx.request({
			 url: 'http://服务器公网ip:80/sign/' + userId,
			 method: "GET",
			 success: function (res) {
				 if (res.data.status == 1) {
					 that.setData({
						 total_sign: that.data.total_sign+1,
						 signed: true,
					 })
					 wx.showToast({
						 title: '成功',
						 icon: 'success',
						 duration: 2000
					 })
				 }
				 else {
					 console.log("status error: " + res.data.Exception)
				 }
			 },
		 })
	 },
})